Skip to content

outlook: Authenticate emulator Graph requests - #3088

Open
gentlemandev wants to merge 1 commit into
mainfrom
fix/outlook-emulator-auth-header-qa-3081
Open

outlook: Authenticate emulator Graph requests#3088
gentlemandev wants to merge 1 commit into
mainfrom
fix/outlook-emulator-auth-header-qa-3081

Conversation

@gentlemandev

@gentlemandev gentlemandev commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

TL;DR

Authenticate Microsoft Graph requests to the local HTTP emulator while leaving the production Graph client path unchanged.

What changed

  • replace the Graph SDK authentication handler only for custom emulator base URLs, preserving the default retry, redirect, telemetry, and HTTP middleware
  • add a real HTTP regression test that verifies the emulator receives the bearer token
  • update the existing Outlook client configuration test for middleware initialization

Root cause

QA for #3081 found that the Graph SDK 3.x authentication middleware removes authorization from HTTP custom hosts. The emulator token itself was valid, but app requests reached the Microsoft emulator without an Authorization header and returned 401.

Validation

  • pnpm test utils/outlook/client.test.ts utils/outlook/client.emulator.test.ts (4 tests)
  • pnpm test utils/outlook/message.test.ts (63 tests)
  • pnpm test-integration provider-operations (19 tests)
  • pnpm exec ultracite check ... on the affected and original PR files
  • authenticated Outlook browser/API smoke against emulate.dev: /api/messages returned the seeded messages and AI Chat returned the expected text-search result

Review in cubic

@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
inbox-zero Ignored Ignored Jul 29, 2026 1:07pm

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/web/utils/outlook/client.ts">

<violation number="1" location="apps/web/utils/outlook/client.ts:286">
P1: Emulator Graph requests fail before reaching the HTTP server because the replacement authentication handler has no `nextMiddleware`: replacing `middleware[0]` discards the linked first handler, but this new instance never receives `setNext`. Linking it to `middleware[1]` (or otherwise preserving the existing chain) keeps the default retry, redirect, telemetry, and HTTP handlers while allowing the bearer header to be added.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


// Graph SDK 3.x only authenticates HTTPS custom hosts, while emulate.dev
// intentionally serves its local Microsoft endpoint over HTTP.
middleware[0] = new MicrosoftEmulatorAuthenticationHandler(accessToken);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Emulator Graph requests fail before reaching the HTTP server because the replacement authentication handler has no nextMiddleware: replacing middleware[0] discards the linked first handler, but this new instance never receives setNext. Linking it to middleware[1] (or otherwise preserving the existing chain) keeps the default retry, redirect, telemetry, and HTTP handlers while allowing the bearer header to be added.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/web/utils/outlook/client.ts, line 286:

<comment>Emulator Graph requests fail before reaching the HTTP server because the replacement authentication handler has no `nextMiddleware`: replacing `middleware[0]` discards the linked first handler, but this new instance never receives `setNext`. Linking it to `middleware[1]` (or otherwise preserving the existing chain) keeps the default retry, redirect, telemetry, and HTTP handlers while allowing the bearer header to be added.</comment>

<file context>
@@ -258,3 +275,41 @@ export function getLinkingOAuth2Url() {
+
+  // Graph SDK 3.x only authenticates HTTPS custom hosts, while emulate.dev
+  // intentionally serves its local Microsoft endpoint over HTTP.
+  middleware[0] = new MicrosoftEmulatorAuthenticationHandler(accessToken);
+
+  return middleware;
</file context>
Suggested change
middleware[0] = new MicrosoftEmulatorAuthenticationHandler(accessToken);
const authenticationHandler = new MicrosoftEmulatorAuthenticationHandler(
accessToken,
);
authenticationHandler.setNext(middleware[1]);
middleware[0] = authenticationHandler;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants